<?php

namespace app\api\controller\ytjk;

use app\api\controller\Base;
use app\server\ExtraPathServer;
use app\server\HredisServer;
use app\server\RegionServer;
use \think\facade\Db;

class Nav extends Base
{
    protected $now;
    protected $currentVersion;
    protected $navArr = [
        [
            'name' => 'examine',
            'text' => '做题',
            'img' => 'notification-filled',
            'path' => '/pages/Index?aa=bb&cc=dd',
            'appId' => ''
        ],
        [
            'name' => 'my',
            'text' => '我的',
            'img' => 'person-filled',
            'path' => '/pages/My',
            'appId' => ''
        ],
    ];

    public function __construct()
    {
        parent::__construct(); // TODO: Change the autogenerated stub
        $this->now = time();
        $params = $this->params;
        $config = config($params['app']);
        $this->currentVersion = $config['quick']['huawei']['currentVersion'];
    }



    public function index()
    {
        $params = $this->params;
        $navArr = $this->navArr;
        $pass = 0;
        if($params['app_version'] <= $this->currentVersion){
            $navArrPass = [
                [
                    'name' => 'home',
                    'text' => '报名',
                    'img' => 'navigate-filled',
                    'path' => '/pages/Sign',
                    'appId' => ''
                ],
                [
                    'name' => 'examine',
                    'text' => '做题',
                    'img' => 'notification-filled',
                    'path' => '/pages/Index?aa=bb&cc=dd',
                    'appId' => ''
                ],
                [
                    'name' => 'task',
                    'text' => '任务',
                    'img' => 'notification-filled',
                    'path' => '/pages/Task',
                    'appId' => ''
                ],
                [
                    'name' => 'my',
                    'text' => '我的',
                    'img' => 'person-filled',
                    'path' => '/pages/My',
                    'appId' => ''
                ],
            ];
            $params = $this->params;
            if($this->now - $params['utime'] > 1800){
                $pass = 1;
            }
            if ($pass ==0 && $params['app_version'] < $this->currentVersion) {
                $pass = 1;
            }
            if($pass ==0){
                $row = find("app_kyy_user",'id,uuid,pass',['uuid'=>$params['uuid']]);
                if(!empty($row) && $row['pass'] == 1){
                    $pass = 1;
                }
            }
            if($pass == 1){
                $navArr = $navArrPass;
            }
//            if($pass) {
//                $row = app(ExtraPathServer::class)->getPath($params);
//                if(!empty($row)){
//                    $navArr[] = [
//                        'name' => 'task',
//                        'text' => '提现',
//                        'img' => 'notification-filled',
//                        'path' => $row['path'],
//                        'appId' => ''
//                    ];
//                }
//            }

        }
        $this->success('success',['list'=>$navArr,'pass'=>$pass,'tt'=>$this->now - $params['utime']]);
    }

}
